package algorithm.view.prepare;

import algorithm.view.common.AlgoHelpler;

import java.awt.*;

/**
 * @author bingo
 * @Description
 * @Date 2018/4/29
 */
public class AlgoVisualizer {

    private AlgoFrame algoFrame;

    private Circle[] circles;


    public AlgoVisualizer(int senceWeight,int senceHeight,int N,int R) {
        circles = new Circle[N];
        for(int i=0;i<N;i++){
            int x = (int)(Math.random()*(senceWeight-2*R))+R;
            int y = (int)(Math.random()*(senceHeight-2*R))+R;
            int vx = (int)(Math.random()*11)-5;
            int vy = (int)(Math.random()*11)-5;
            circles[i] = new Circle(x,y,R,vx,vy);
        }
        EventQueue.invokeLater(()-> {
           algoFrame = new AlgoFrame("welcome", senceWeight, senceHeight);
            AlgoHelpler.pause(1000);
            new Thread(()->{
                while (true) {
                    /**绘制动画*/
                    algoFrame.render(circles);
                    AlgoHelpler.pause(10);
                    /**更新动画*/
                    for (Circle circle : circles) {
                        circle.move(0,senceWeight,0,senceHeight);
                    }

                }
            }).start();

        });
    }
}
